package api

import (
	"2302a/tiktok_business/api/handler"
	"2302a/tiktok_business/api/middleware"
	"2302a/tiktok_business/consts"
	"2302a/tiktok_business/pkg"
	"github.com/gin-gonic/gin"
)

func LoadRouter(r *gin.Engine) {
	r.Use(middleware.Cors())
	api := r.Group("api")
	{
		user := api.Group("user") //用户模块
		{
			user.POST("/register", handler.UserRegister) //注册
			user.POST("/login", handler.UserLogin)       //登录
			user.POST("/send", handler.SendSms)          //短信
		}
		file := api.Group("file")
		{
			file.POST("/upload", handler.FileUpload) //上传图片
		}
		video := api.Group("video") //视频模块
		{
			video.Use(pkg.AuthJwt(consts.JWT_KEY))
			video.POST("/add", handler.AddVideo)
			video.GET("/list", handler.ListVideo)     //实现首页视频分页加载
			video.GET("/status", handler.StatusVideo) //视频播放控制状态
			video.GET("/browse", handler.BrowseVideo) //将用户最近浏览的 10 条视频
			video.GET("/search", handler.SearchVideo) //根据用户设置的地区
		}
		chat := api.Group("chat")
		{
			chat.Use(pkg.AuthJwt(consts.JWT_KEY))
			chat.GET("/personal", handler.Personal) //实现个人主页
			chat.GET("/ws", handler.Chat)           //私信发送功能
		}
		comment := api.Group("comment")
		{
			comment.Use(pkg.AuthJwt(consts.JWT_KEY))
			comment.POST("/add", handler.AddComment)
			comment.POST("/Like", handler.LikeComment)
			comment.POST("/update", handler.UpdateComment)
		}
		messages := api.Group("messages")
		{
			messages.Use(pkg.AuthJwt(consts.JWT_KEY))
			messages.POST("/add", handler.AddMessage)       //消息
			messages.POST("/unread", handler.UnreadMessage) //未读消息
		}
		barrages := api.Group("barrages")
		{
			barrages.Use(pkg.AuthJwt(consts.JWT_KEY))
			barrages.POST("/add", handler.AddBarrages)
		}
	}
}
